class_name PlayerStatePreppingShoot
extends PlayerState

const DURATION_MAX_BONUS := 1000.0
const EASE_REWARD_FACTOR := 2.0

#射击方向，允许玩家在pre阶段通过控制上下左右键设置
var shot_direction := Vector2.ZERO
#射击蓄力时间计算
var time_start_shot := Time.get_ticks_msec()

func _enter_tree() -> void:
	animation_player.play("prep_kick")
	player.velocity = Vector2.ZERO
	time_start_shot = Time.get_ticks_msec()
	shot_direction = player.heading
	
	
func _process(delta: float) -> void:
	#这个地方的设计思路是，在准备期间，玩家按上下左右，会记录每次玩家按的时间长度的向量，累加
	shot_direction += KeyUtils.get_input_vector(player.control_scheme) * delta
	#射击按钮松开了，可以进行射击，这里先对准备期间的操作进行统计，以算出下一步的射击参数
	if KeyUtils.is_action_just_released(player.control_scheme,KeyUtils.Action.SHOOT):
		var duration_press = clampf(Time.get_ticks_msec()-time_start_shot,0.0,DURATION_MAX_BONUS)
		var ease_time = duration_press /DURATION_MAX_BONUS
		#威力计算
		var bonus := ease(ease_time,EASE_REWARD_FACTOR)
		var shot_power = player.power * (1 + bonus)
		shot_direction = shot_direction.normalized()
		var context_state_data = PlayerStateData.build().set_shot_power(shot_power).set_shot_direction(shot_direction)
		transition_state(Player.State.SHOOTING,context_state_data)
func can_pass() -> bool:
	return false
